-- initJustice
-- Created by huanghr Mar/14/2016
-- 正义使者格子

local JUSTICE_PET_ID = 45;  -- 正义使者编号

-- 初始化
function initJustice(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local iconPath = getHeroIconPath(JUSTICE_PET_ID);

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            local function okFunc()
                local pos = self.gridData:getPos();
                DungeonActionM.go("do_building_bonus", pos);
            end
            self:openBuildingView(okFunc, nil, nil, nil, nil, iconPath);
        end
    end

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.item:setPositionX(5);
    self.item:setPositionY(5);
    self.icon:setScale(1.2);

    -- 模型呼吸
    self:doModelBreath(self.icon);
end

